package concurent;

import org.junit.Test;

import java.util.*;


public class HashSetDemo {

    @Test
    public void t1() {

        User u1 = new User(1L, "root");
        User u2 = new User(2L, "root");
        User u3 = new User(3L, "root");

        LinkedHashSet<User> s = new LinkedHashSet<>();
        s.add(u1);
        s.add(u2);
        s.add(u3);
        System.out.println(s);


        HashMap<User, String> map = new HashMap<>(2);
        map.put(u1, "aaa");
        map.put(u2, "bbb");
        System.out.println(map.size());
    }
}

class User {
    private Long id;
    private String name;

    public User(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof User)) return false;
        User user = (User) o;
        return id.equals(user.id) && name.equals(user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @Test
    public void t111() {
        List list = new ArrayList<>();

        list.add(1);
        list.add(2);
        list.add(3);


    }
}
